Ottawa

row

Buildings

146,880

Users

200

Average number of tags

4.2

row

Buildings mapped

row

Buildings by type

Missing address fields in percentage

Number of tags

Gatineau

row

Buildings

69,328

Users

106

Average number of tags

5.92

row

Buildings mapped

row

Buildings by type

Missing address fields in percentage

Number of tags

Ottawa-Gatineau

row

Buildings

216,207

Users

264

Average number of tags

4.75

row

Buildings mapped

row

Buildings by type

Missing address fields in percentage

Number of tags

Data

August 2016

February 2017

---
title: "Crowdsourcing - February 2017"
output: 
  flexdashboard::flex_dashboard:
    theme: lumen
    orientation: rows
    source_code: embed
---

```{r global, include=FALSE}
library(flexdashboard)
library(tidyverse)
library(ggthemes)
library(lubridate)
library(leaflet)
library(rgdal)
library(forcats)
library(scales)
library(DT)
library(plotly)

data <- read.csv('~/Projects/CrowdAnalysis/Buildings.csv', header = TRUE)
data2 <- data
data3 <- data
data$averTagsBuild <- round(data$averTagsBuild, 2)
data$month <- month(data$month, label = TRUE)
data2$month <- ymd(data2$month)

BuildOtt <- readOGR("../OSMdata/07 - February2017/OttBuildW.geojson", 
                    "OGRGeoJSON", require_geomType="wkbPolygon")

BuildGat <- readOGR("../OSMdata/07 - February2017/GatBuildW.geojson", 
                    "OGRGeoJSON", require_geomType="wkbPolygon")

BuildOttGat <- readOGR("../OSMdata/07 - February2017/OttGatBuildW.geojson", 
                    "OGRGeoJSON", require_geomType="wkbPolygon")
```

Ottawa {data-navmenu="Cities"}
=======================================================================
row
-----------------------------------------------------------------------

###Buildings {.value-box}
```{r, echo=FALSE}
buildOtt <- data %>%
  filter(cities == "Ottawa") %>%
  filter(month == "Feb") %>%
  select(buildings)

valueBox(comma(buildOtt), icon = "ion-ios-home-outline", color = "#9ecae1")
```

###Users {.value-box}
```{r}
usersOtt <- data %>%
  filter(cities == "Ottawa") %>%
  filter(month == "Feb") %>%
  select(usersBuild)

valueBox(usersOtt, icon = "ion-ios-people-outline", color = "#9ecae1")
```

###Average number of tags {.value-box}
```{r}
tagsOtt <- data %>%
  filter(cities == "Ottawa") %>%
  filter(month == "Feb") %>%
  select(averTagsBuild)

tagsOtt$averTagsBuild <- round(tagsOtt$averTagsBuild, 2)

valueBox(tagsOtt, icon = "ion-ios-pricetags-outline", color = "#9ecae1")
```


row {data-height=400}
-----------------------------------------------------------------------

###Buildings mapped

```{r, echo=FALSE, message=FALSE}
 OttBuild <- data2 %>%
   filter(cities=="Ottawa") %>%
   select(cities, month, buildings)

#With a geom_line plot, you need to add group = 1 if only one group of observations
#to avoid the warning message each is obs is one group
gg <- ggplot(OttBuild, aes(month, buildings, group = 1, text = comma(buildings)))
gg <- gg + geom_line(position = "identity", color="#6baed6")
gg <- gg + scale_y_continuous(labels = comma)
gg <- gg + scale_x_date(breaks = as.Date(seq(as.Date("2016-07-15"), 
                            as.Date("2017-02-15"), by = "1 month")), date_labels ="%b %y")
gg <- gg + labs(x = NULL, y = NULL)
gg <- gg + theme(strip.background=element_blank())
gg <- gg + theme_bw(base_family = "Helvetica")
gg <- gg + theme(panel.border = element_blank())
gg <- gg + theme(panel.grid.major.x= element_blank())
gg <- gg + theme(panel.grid.major.y=element_line(linetype = "dashed"))
gg <- gg + theme(panel.grid.minor = element_blank())
gg <- gg + theme(axis.ticks=element_line(colour="#ececec"))
gg <- gg + theme(axis.text.x=element_text(size=12))
gg <- gg + theme(axis.text.y=element_text(size=10))
ggplotly(gg, tooltip = "text")
```

row {data-height=600}
-------------------------------------------------------------------
###Buildings by type 
```{r}
buildType <- BuildOtt@data %>% 
  group_by(building) %>%
  summarise(numB = length(building)) %>%
  arrange(desc(numB)) %>%
  filter(numB > 50)

gg <- ggplot(buildType, aes(x=numB, y=reorder(building, numB), text = comma(numB)))
gg <- gg + geom_segment(aes(xend = 0, yend=building), color="#ececec")
gg <- gg + geom_point(color = "#3282bd", size = 2)
gg <- gg + scale_x_continuous(expand = c(0.1,0), labels = comma)
gg <- gg + labs(x = NULL, y = NULL)
gg <- gg + theme(strip.background=element_blank())
gg <- gg + theme_bw(base_family = "Helvetica")
gg <- gg + theme(panel.border = element_blank())
gg <- gg + theme(panel.grid.major = element_blank())
gg <- gg + theme(panel.grid.minor = element_blank())
gg <- gg + theme(axis.ticks.y=element_blank())
gg <- gg + theme(axis.text.x=element_text(size=9))
gg <- gg + theme(axis.text.y=element_text(size=12))
ggplotly(gg, tooltip = "text")
```

### Missing address fields in percentage
```{r}

MissAddOtt <- BuildOtt@data %>%
  select(addr.street, addr.housenumber, addr.city, addr.postcode)


MeanAddrOtt <- MissAddOtt %>%
  summarise_all(funs(mean(is.na(.))*100)) %>%
  gather(Field, meanNA) %>%
  mutate(Field = fct_recode(Field, "Street" = "addr.street", 
                            "Street Number" = "addr.housenumber",
                            "City" = "addr.city",
                            "Postal Code" = "addr.postcode"))

gg <- ggplot(MeanAddrOtt, aes(x=reorder(Field, meanNA), y=meanNA, text = round(meanNA, 2)))
gg <- gg + geom_segment(aes(xend = Field, yend=0), color="#ececec")
gg <- gg + geom_point(color = "#3282bd", size = 2)
gg <- gg + coord_flip()
gg <- gg + labs(x = NULL, y = NULL)
gg <- gg + theme(strip.background=element_blank())
gg <- gg + theme_bw(base_family = "Helvetica")
gg <- gg + theme(panel.border = element_blank())
gg <- gg + theme(panel.grid.major = element_blank())
gg <- gg + theme(panel.grid.minor = element_blank())
gg <- gg + theme(axis.ticks.y=element_blank())
gg <- gg + theme(axis.text.x=element_text(size=10))
gg <- gg + theme(axis.text.y=element_text(size=12))
ggplotly(gg, tooltip = "text")
```


###Number of tags
```{r}

OttTagsBuild <- data3 %>%
  filter(cities=="Ottawa") %>%
  select(cities, month, tagsBuild) %>%
  mutate(month = fct_recode(month, "2016-08-30" = "2016-08-01")) %>%
  mutate(month = ymd(month))

gg <- ggplot(OttTagsBuild, aes(x=tagsBuild, y=month, text = comma(tagsBuild)))
gg <- gg + geom_segment(aes(xend = 0, yend=month), color="#ececec")
gg <- gg + geom_point(color = "#3282bd", size = 2)
gg <- gg + scale_x_continuous(expand = c(0.1,0), labels = comma)
gg <- gg + scale_y_date(breaks = as.Date(seq(as.Date("2016-08-28"), 
                            as.Date("2017-02-28"), by = "1 month")), date_labels ="%b %y")
gg <- gg + labs(x = NULL, y = NULL)
gg <- gg + theme(strip.background=element_blank())
gg <- gg + theme_bw(base_family = "Helvetica")
gg <- gg + theme(panel.border = element_blank())
gg <- gg + theme(panel.grid.major = element_blank())
gg <- gg + theme(panel.grid.minor = element_blank())
gg <- gg + theme(axis.ticks.y=element_blank())
gg <- gg + theme(axis.text.x=element_text(size=10))
gg <- gg + theme(axis.text.y=element_text(size=12))
ggplotly(gg, tooltip = "text")
```

Gatineau {data-navmenu="Cities"}
=======================================================================
row
-----------------------------------------------------------------------

###Buildings {.value-box}
```{r, echo=FALSE}
buildGat <- data %>%
  filter(cities == "Gatineau") %>%
  filter(month == "Feb") %>%
  select(buildings)

valueBox(comma(buildGat), icon = "ion-ios-home-outline", color = "#9ecae1")
```

###Users {.value-box}
```{r}
usersGat <- data %>%
  filter(cities == "Gatineau") %>%
  filter(month == "Feb") %>%
  select(usersBuild)

valueBox(usersGat, icon = "ion-ios-people-outline", color = "#9ecae1")
```

###Average number of tags {.value-box}
```{r}
tagsGat <- data %>%
  filter(cities == "Gatineau") %>%
  filter(month == "Feb") %>%
  select(averTagsBuild)

tagsGat$averTagsBuild <- round(tagsGat$averTagsBuild, 2)

valueBox(tagsGat, icon = "ion-ios-pricetags-outline", color = "#9ecae1")
```


row {data-height=400}
-----------------------------------------------------------------------

###Buildings mapped
```{r, echo=FALSE, message=FALSE}
 GatBuild <- data2 %>%
   filter(cities=="Gatineau") %>%
   select(cities, month, buildings)

#With a geom_line plot, you need to add group = 1 if only one group of observations
#to avoid the warning message each is obs is one group
gg <- ggplot(GatBuild, aes(month, buildings, group = 1, text = comma(buildings)))
gg <- gg + geom_line(position = "identity", color="#6baed6")
gg <- gg + scale_y_continuous(labels = comma)
gg <- gg + scale_x_date(breaks = as.Date(seq(as.Date("2016-07-15"), 
                            as.Date("2017-02-15"), by = "1 month")), date_labels ="%b %y")
gg <- gg + labs(x = NULL, y = NULL)
gg <- gg + theme(strip.background=element_blank())
gg <- gg + theme_bw(base_family = "Helvetica")
gg <- gg + theme(panel.border = element_blank())
gg <- gg + theme(panel.grid.major.x= element_blank())
gg <- gg + theme(panel.grid.major.y=element_line(linetype = "dashed"))
gg <- gg + theme(panel.grid.minor = element_blank())
gg <- gg + theme(axis.ticks=element_line(colour="#ececec"))
gg <- gg + theme(axis.text.x=element_text(size=12))
gg <- gg + theme(axis.text.y=element_text(size=10))
ggplotly(gg, tooltip = "text")
```

row {data-height=600}
-------------------------------------------------------------------
###Buildings by type
```{r}
buildTypeGat <- BuildGat@data %>% 
  group_by(building) %>%
  summarise(numB = length(building)) %>%
  arrange(desc(numB)) %>%
  filter(numB > 50)

gg <- ggplot(buildTypeGat, aes(x=numB, y=reorder(building, numB), text = comma(numB)))
gg <- gg + geom_segment(aes(xend = 0, yend=building), color="#ececec")
gg <- gg + geom_point(color = "#3282bd", size = 2)
gg <- gg + scale_x_continuous(expand = c(0.1,0), labels = comma)
gg <- gg + labs(x = NULL, y = NULL)
gg <- gg + theme(strip.background=element_blank())
gg <- gg + theme_bw(base_family = "Helvetica")
gg <- gg + theme(panel.border = element_blank())
gg <- gg + theme(panel.grid.major = element_blank())
gg <- gg + theme(panel.grid.minor = element_blank())
gg <- gg + theme(axis.ticks.y=element_blank())
gg <- gg + theme(axis.text.x=element_text(size=9))
gg <- gg + theme(axis.text.y=element_text(size=12))
ggplotly(gg, tooltip = "text")
```

### Missing address fields in percentage
```{r}

MissAddGat <- BuildGat@data %>%
  select(addr.street, addr.housenumber, addr.city, addr.postcode)


MeanAddrGat <- MissAddGat %>%
  summarise_all(funs(mean(is.na(.))*100)) %>%
  gather(Field, meanNA) %>%
  mutate(Field = fct_recode(Field, "Street" = "addr.street", 
                            "Street Number" = "addr.housenumber",
                            "City" = "addr.city",
                            "Postal Code" = "addr.postcode"))

gg <- ggplot(MeanAddrGat, aes(x=reorder(Field, meanNA), y=meanNA, text = round(meanNA, 2)))
gg <- gg + geom_segment(aes(xend = Field, yend=0), color="#ececec")
gg <- gg + geom_point(color = "#3282bd", size = 2)
gg <- gg + coord_flip()
gg <- gg + labs(x = NULL, y = NULL)
gg <- gg + theme(strip.background=element_blank())
gg <- gg + theme_bw(base_family = "Helvetica")
gg <- gg + theme(panel.border = element_blank())
gg <- gg + theme(panel.grid.major = element_blank())
gg <- gg + theme(panel.grid.minor = element_blank())
gg <- gg + theme(axis.ticks.y=element_blank())
gg <- gg + theme(axis.text.x=element_text(size=10))
gg <- gg + theme(axis.text.y=element_text(size=12))
ggplotly(gg, tooltip = "text")
```

###Number of tags

```{r}

GatTagsBuild <- data3 %>%
  filter(cities=="Gatineau") %>%
  select(cities, month, tagsBuild) %>%
  mutate(month = fct_recode(month, "2016-08-30" = "2016-08-01")) %>%
  mutate(month = ymd(month))

#28 because of February
gg <- ggplot(GatTagsBuild, aes(x=tagsBuild, y=month, text = comma(tagsBuild)))
gg <- gg + geom_segment(aes(xend = 0, yend=month), color="#ececec")
gg <- gg + geom_point(color = "#3282bd", size = 2)
gg <- gg + scale_x_continuous(expand = c(0.1,0), labels = comma)
gg <- gg + scale_y_date(breaks = as.Date(seq(as.Date("2016-08-28"), 
                            as.Date("2017-02-28"), by = "1 month")), date_labels ="%b %y")
gg <- gg + labs(x = NULL, y = NULL)
gg <- gg + theme(strip.background=element_blank())
gg <- gg + theme_bw(base_family = "Helvetica")
gg <- gg + theme(panel.border = element_blank())
gg <- gg + theme(panel.grid.major = element_blank())
gg <- gg + theme(panel.grid.minor = element_blank())
gg <- gg + theme(axis.ticks.y=element_blank())
gg <- gg + theme(axis.text.x=element_text(size=10))
gg <- gg + theme(axis.text.y=element_text(size=12))
ggplotly(gg, tooltip = "text")
```

Ottawa-Gatineau {data-navmenu="Cities"}
=======================================================================
row
-----------------------------------------------------------------------

###Buildings {.value-box}
```{r, echo=FALSE}
buildOttGat <- data %>%
  filter(cities == "Ott/Gat") %>%
  filter(month == "Feb") %>%
  select(buildings)

valueBox(comma(buildOttGat), icon = "ion-ios-home-outline", color = "#9ecae1")
```

###Users {.value-box}
```{r}
usersOttGat <- data %>%
  filter(cities == "Ott/Gat") %>%
  filter(month == "Feb") %>%
  select(usersBuild)

valueBox(usersOttGat, icon = "ion-ios-people-outline", color = "#9ecae1")
```

###Average number of tags {.value-box}
```{r}
tagsOttGat <- data %>%
  filter(cities == "Ott/Gat") %>%
  filter(month == "Feb") %>%
  select(averTagsBuild)

tagsOtt$averTagsBuild <- round(tagsOttGat$averTagsBuild, 2)

valueBox(tagsOttGat, icon = "ion-ios-pricetags-outline", color = "#9ecae1")
```


row {data-height=400}
-----------------------------------------------------------------------

###Buildings mapped

```{r, echo=FALSE, message=FALSE}
 OttBuildGat <- data2 %>%
   filter(cities=="Ott/Gat") %>%
   select(cities, month, buildings)

#With a geom_line plot, you need to add group = 1 if only one group of observations
#to avoid the warning message each is obs is one group
gg <- ggplot(OttBuildGat, aes(month, buildings, group = 1, text = comma(buildings)))
gg <- gg + geom_line(position = "identity", color="#6baed6")
gg <- gg + scale_y_continuous(labels = comma)
gg <- gg + scale_x_date(breaks = as.Date(seq(as.Date("2016-07-15"), 
                            as.Date("2017-02-15"), by = "1 month")), date_labels ="%b %y")
gg <- gg + labs(x = NULL, y = NULL)
gg <- gg + theme(strip.background=element_blank())
gg <- gg + theme_bw(base_family = "Helvetica")
gg <- gg + theme(panel.border = element_blank())
gg <- gg + theme(panel.grid.major.x= element_blank())
gg <- gg + theme(panel.grid.major.y=element_line(linetype = "dashed"))
gg <- gg + theme(panel.grid.minor = element_blank())
gg <- gg + theme(axis.ticks=element_line(colour="#ececec"))
gg <- gg + theme(axis.text.x=element_text(size=12))
gg <- gg + theme(axis.text.y=element_text(size=10))
ggplotly(gg, tooltip = "text")
```

row {data-height=600}
-------------------------------------------------------------------
###Buildings by type
```{r}
buildTypeOttGat <- BuildOttGat@data %>% 
  group_by(building) %>%
  summarise(numB = length(building)) %>%
  arrange(desc(numB)) %>%
  filter(numB > 50)

gg <- ggplot(buildTypeOttGat, aes(x=numB, y=reorder(building, numB), text = comma(numB)))
gg <- gg + geom_segment(aes(xend = 0, yend=building), color="#ececec")
gg <- gg + geom_point(color = "#3282bd", size = 2)
gg <- gg + scale_x_continuous(expand = c(0.1,0), labels = comma)
gg <- gg + labs(x = NULL, y = NULL)
gg <- gg + theme(strip.background=element_blank())
gg <- gg + theme_bw(base_family = "Helvetica")
gg <- gg + theme(panel.border = element_blank())
gg <- gg + theme(panel.grid.major = element_blank())
gg <- gg + theme(panel.grid.minor = element_blank())
gg <- gg + theme(axis.ticks.y=element_blank())
gg <- gg + theme(axis.text.x=element_text(size=9))
gg <- gg + theme(axis.text.y=element_text(size=12))
ggplotly(gg, tooltip = "text")
```

### Missing address fields in percentage
```{r}

MissAddOttGat <- BuildOttGat@data %>%
  select(addr.street, addr.housenumber, addr.city, addr.postcode)

MeanAddrOttGat <- MissAddOttGat %>%
  summarise_all(funs(mean(is.na(.))*100)) %>%
  gather(Field, meanNA) %>%
  mutate(Field = fct_recode(Field, "Street" = "addr.street", 
                            "Street Number" = "addr.housenumber",
                            "City" = "addr.city",
                            "Postal Code" = "addr.postcode"))

gg <- ggplot(MeanAddrOttGat, aes(x=reorder(Field, meanNA), y=meanNA, text = round(meanNA, 2)))
gg <- gg + geom_segment(aes(xend = Field, yend=0), color="#ececec")
gg <- gg + geom_point(color = "#3282bd", size = 2)
gg <- gg + coord_flip()
gg <- gg + labs(x = NULL, y = NULL)
gg <- gg + theme(strip.background=element_blank())
gg <- gg + theme_bw(base_family = "Helvetica")
gg <- gg + theme(panel.border = element_blank())
gg <- gg + theme(panel.grid.major = element_blank())
gg <- gg + theme(panel.grid.minor = element_blank())
gg <- gg + theme(axis.ticks.y=element_blank())
gg <- gg + theme(axis.text.x=element_text(size=10))
gg <- gg + theme(axis.text.y=element_text(size=12))
ggplotly(gg, tooltip = "text")
```

###Number of tags

```{r}
OttGatTagsBuild <- data3 %>%
  filter(cities=="Ott/Gat") %>%
  select(cities, month, tagsBuild) %>%
  mutate(month = fct_recode(month, "2016-08-30" = "2016-08-01")) %>%
  mutate(month = ymd(month))

#28 because of February
gg <- ggplot(OttGatTagsBuild, aes(x=tagsBuild, y=month, text = comma(tagsBuild)))
gg <- gg + geom_segment(aes(xend = 0, yend=month), color="#ececec")
gg <- gg + geom_point(color = "#3282bd", size = 2)
gg <- gg + scale_x_continuous(expand = c(0.2,0), labels = comma)
gg <- gg + scale_y_date(breaks = as.Date(seq(as.Date("2016-08-28"), 
                            as.Date("2017-02-28"), by = "1 month")), date_labels ="%b %y")
gg <- gg + labs(x = NULL, y = NULL)
gg <- gg + theme(strip.background=element_blank())
gg <- gg + theme_bw(base_family = "Helvetica")
gg <- gg + theme(panel.border = element_blank())
gg <- gg + theme(panel.grid.major = element_blank())
gg <- gg + theme(panel.grid.minor = element_blank())
gg <- gg + theme(axis.ticks.y=element_blank())
gg <- gg + theme(axis.text.x=element_text(size=10))
gg <- gg + theme(axis.text.y=element_text(size=12))
ggplotly(gg, tooltip = "text")
```


Data
========================================================
```{r}
datatable(data, extensions = "Buttons", 
          options = list(dom="lfrtBip", buttons="csv"))
```


August 2016 {data-navmenu="Maps"}
========================================================
```{r, out.width = "1024px"}
knitr::include_graphics("/Users/bjenkellefsen/Projects/JARCID/August2016.jpg")
```

February 2017 {data-navmenu="Maps"}
========================================================
```{r, out.width = "1024px"}
knitr::include_graphics("/Users/bjenkellefsen/Projects/JARCID/February2017.jpg")
```